# -*- coding: utf-8 -*-


print("此算法用于计算两条直线的交点")
def get_k_b(x1,y1,x2,y2):
    if x1-x2 !=0:
        k = (y1-y2)/(x1-x2)
        b = (x1*y2-y1*x2)/(x1-x2)
    else:
        k = None
        b = x1
    return k,b

def get_intersection_point(k1,b1,k2,b2):
    if k1!=None and k2 !=None:
        point_x = (b2-b1)/(k1-k2)
        point_y = k1*point_x+b1
        return point_x,point_y
    elif k1==None and k2:
        return b1,k2*b1+b2
    elif k2==None and k1:
        return b2,k1*b2+b1
    else:
        if abs(b1-b2)<=0.5:
            return b2
        else:
            return None

def computer_the_point(x1,y1,x2,y2,x3,y3,x4,y4):
    k1,b1 = get_k_b(x1,y1,x2,y2)
    k2,b2 = get_k_b(x3,y3,x4,y4)
    return get_intersection_point(k1,b1,k2,b2)

print(computer_the_point(1,2,5,1,3,1,-1,8))